// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cstdint>

namespace cantor::common {
    class Location {
        static constexpr const int32_t INVALID_INDEX = int32_t(-1);

    public:
        Location() = default;

        ~Location() = default;

        Location(int32_t index, int32_t len) : _index(index), _len(len) {
        }

        static Location Invalid() {
            return Location();
        }

        bool is_valid() const {
            return _index != INVALID_INDEX;
        }

        void set_invalid() {
            _index = INVALID_INDEX;
            _len = 0;
        }

        int32_t get_index() const {
            return _index;
        }

        bool operator==(const Location &rhs) const {
            return _index == rhs._index && _len == rhs._len;
        }

        bool operator!=(const Location &rhs) const {
            return _index != rhs._index || _len != rhs._len;
        }

    private:
        int32_t _index{INVALID_INDEX};
        int32_t _len{0};
    };
} // namespace cantor::common
